Reads the value stored at key in target, a map
map_get(target, key) -> element| Name | Type |
|---|---|
target | map |
key | mapkey |
element
Reads the value stored at key in target, a map<K,V> - a container that looks values up by key instead of by position.
If key is not present, nothing is changed and a plain default value is returned instead (0/0.0/false/an empty string/nothing, depending on target's value type) - target never crashes. Check map_has(target, key) first if the game needs to tell "key really maps to this value" apart from "key was not present."
map<K,V> has no [i] indexing - unlike array<T>/list<T>/grid<T>, a value is only ever reached by key, through this function. Declare the variable list<T> instead if you need to look inside it by position.
/// @type {map<string,int>}
var scores = {};
map_set(scores, "alice", 10);
var score = map_get(scores, "alice"); // 10
var missing = map_get(scores, "bob"); // 0 - "bob" was never set, so this is the default, not a real score



A find() then a ternary (the hash map's find - O(1) average) - deliberately NOT at()/operator[] (both can abort or silently insert on a missing/full key, see this file's own Maps group header). No allocation, no new engine primitive.